package com.tensquare.base.controller;

import entity.Result;
import entity.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: tensquare-project
 * @description: 全局异常处理
 **/
@ControllerAdvice
@ResponseBody
@Slf4j
public class BaseHandlerException {

    @ExceptionHandler// 当捕获到controller层发生异常执行该方法
    public Result error(Exception e){
        e.printStackTrace();
        log.error("发生异常：类名{}",this.getClass().getSimpleName(), e);
        return new Result(false, StatusCode.ERROR, "执行异常:"+e.getMessage(), null);
    }

}
